### Alizade, Dancygier, Ditlmann 
### "National Penalties Reversed"
### Replication Code 
### Table A7
### For questions, contact jalizade@princeton.edu

# empty environment
rm(list = ls())


#setwd("")
setwd("C:/Users/Jey/Dropbox/WZB/NaturalizationExperiment/Submission/JOP/replication_JOP/data")


# load necessary packages
library(readstata13)
library(lmtest)
library(sandwich)


# load data set
dat <- read.dta13("data_experimental.dta")

# convert treatment variable from second experiment to factor
dat$e2_treat[dat$e2_treat=="NA"] <- NA
dat$e2_treat <- factor(dat$e2_treat, levels=c("Vote Intention (Canadian)", "Control (Turkish)", "Vote Intention (Turkish)", "Integration Problems (Turkish)"))


### regressions ###

## only men ##

# study 1 #

# full sample
mod_1 <- lm(e1_response ~ e1_treat_turkish, data=dat)
rob_mod_1 <- coeftest(mod_1, vcov = vcovHC(mod_1, "HC1")) # robust standard errors
rob_mod_1
nobs(mod_1)

# county
mod_2 <- lm(e1_response ~ e1_treat_turkish, data=dat[dat$can_county_male==1,])
rob_mod_2 <- coeftest(mod_2, vcov = vcovHC(mod_2, "HC1")) # robust standard errors
rob_mod_2
nobs(mod_2)

# municipality
mod_3 <- lm(e1_response ~ e1_treat_turkish, data=dat[dat$can_mun_male==1 & !is.na(dat$can_mun_male),])
rob_mod_3 <- coeftest(mod_3, vcov = vcovHC(mod_3, "HC1")) # robust standard errors
rob_mod_3
nobs(mod_3)


# study 2 #

# full sample
mod_4 <- lm(e2_response ~ e2_treat, data=dat[dat$e2_treat=="Vote Intention (Turkish)" | dat$e2_treat=="Vote Intention (Canadian)",])
rob_mod_4 <- coeftest(mod_4, vcov = vcovHC(mod_4, "HC1")) # robust standard errors
rob_mod_4
nobs(mod_4)

# county
mod_5 <- lm(e2_response ~ e2_treat, data=dat[(dat$e2_treat=="Vote Intention (Turkish)" | dat$e2_treat=="Vote Intention (Canadian)") & dat$can_county_male==1,])
rob_mod_5 <- coeftest(mod_5, vcov = vcovHC(mod_5, "HC1")) # robust standard errors
rob_mod_5
nobs(mod_5)

# municipality
mod_6 <- lm(e2_response ~ e2_treat, data=dat[(dat$e2_treat=="Vote Intention (Turkish)" | dat$e2_treat=="Vote Intention (Canadian)") & (dat$can_mun_male==1 & !is.na(dat$can_mun_male)),])
rob_mod_6 <- coeftest(mod_6, vcov = vcovHC(mod_6, "HC1")) # robust standard errors
rob_mod_6
nobs(mod_6)


## men + women ##

# study 1 #

# full sample
# see mod_1

# county
mod_7 <- lm(e1_response ~ e1_treat_turkish, data=dat[dat$can_county==1,])
rob_mod_7 <- coeftest(mod_7, vcov = vcovHC(mod_7, "HC1")) # robust standard errors
rob_mod_7
nobs(mod_7)

# municipality
mod_8 <- lm(e1_response ~ e1_treat_turkish, data=dat[dat$can_mun==1 & !is.na(dat$can_mun),])
rob_mod_8 <- coeftest(mod_8, vcov = vcovHC(mod_8, "HC1")) # robust standard errors
rob_mod_8
nobs(mod_8)


# study 2 #

# full sample
# see mod_4

# county
mod_9 <- lm(e2_response ~ e2_treat, data=dat[(dat$e2_treat=="Vote Intention (Turkish)" | dat$e2_treat=="Vote Intention (Canadian)") & dat$can_county==1,])
rob_mod_9 <- coeftest(mod_9, vcov = vcovHC(mod_9, "HC1")) # robust standard errors
rob_mod_9
nobs(mod_9)

# municipality
mod_10 <- lm(e2_response ~ e2_treat, data=dat[(dat$e2_treat=="Vote Intention (Turkish)" | dat$e2_treat=="Vote Intention (Canadian)") & (dat$can_mun==1 & !is.na(dat$can_mun)),])
rob_mod_10 <- coeftest(mod_10, vcov = vcovHC(mod_10, "HC1")) # robust standard errors
rob_mod_10
nobs(mod_10)
